//
//  PassWordTextField.swift
//  Exchange
//
//  Created by 孟祥群 on 2018/7/27.
//  Copyright © 2018年 common. All rights reserved.
//

import UIKit

class PassWordTextField: BaseTextField {
    var length:Int? //输入的长度
    override init(changeView: UIView?, szBounds: CGRect) {
        super.init(changeView: changeView, szBounds: szBounds)
        self.delegate = self
        self.isSecureTextEntry = true
        self.keyboardType =  UIKeyboardType.asciiCapable
        self.font = UIFont.systemFont(ofSize: 15)
    }
    
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
        if !super.textField(textField, shouldChangeCharactersIn: range, replacementString: string) {
            return false
        }
        let newString = (textField.text! as NSString).replacingCharacters(in: range, with: string)
        if string.count == 0 {
            return true
        }
        if length != nil {
            if newString.count > length! {
                return false
            }
        }
        
        return  textField.judgePassRule(pass: string)
    }
    

    /*
    // Only override draw() if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    override func draw(_ rect: CGRect) {
        // Drawing code
    }
    */

}
